#import "BWJunkyard.h"


NSPoint centerPoint (NSRect rect)
{
    NSPoint point;

    point.x = rect.origin.x + rect.size.width / 2.0;
    point.y = rect.origin.y + rect.size.height / 2.0;

    return (point);

} // centerPoint

BOOL pointNearPoint (NSPoint point, NSPoint center, float radius)
{
    BOOL result = NO;

    if (point.x >= center.x - radius
        && point.x <= center.x + radius
        && point.y >= center.y - radius
        && point.y <= center.y + radius) {
        result = YES;
    }

    return (result);

} // pointNearPoint



float distance (NSPoint point1, NSPoint point2)
{
    float x2mx1, y2my1;
    x2mx1 = point2.x - point1.x;
    y2my1 = point2.y - point1.y;

    float distance;
    distance = sqrt ((x2mx1 * x2mx1) + (y2my1 * y2my1));
    
    return (distance);

} // distance


// radians
float angleForPoints (NSPoint point1, NSPoint point2)
{
    float hyptLength;
    hyptLength = distance (point1, point2);

    // normalize the vector

    // move the vector to the origin
    point2.x -= point1.x;
    point2.y -= point1.y;

    // scale it
    point2.x /= hyptLength;
    point2.y /= hyptLength;

    float angle;
    angle = atan2 (point2.y, point2.x);

    return (angle);

} // angleForPoints


float radiansToDegrees (float angle)
{
    float degrees;

    degrees = angle * (180 / PI);

    return (degrees);

} // radiansToDegrees


float degreesToRadians (float angle)
{
    float radians;

    radians = angle * (PI / 180);

    return (radians);

} // degreesToRadians


BOOL isNaN (float number)
{
    if (number != number) {
        return (YES);
    } else {
        return (NO);
    }

} // isNaN
